package repositories

import (
	"pegasus/utils"
	"pegasus/models"

	"github.com/go-xorm/xorm"
)

type AnnouncementRepo struct {
	logger utils.ILogger
	engine *xorm.Engine
}

func NewAnnouncementRepo(il utils.ILogger, e *xorm.Engine) *AnnouncementRepo {
	return &AnnouncementRepo{
		logger: il,
		engine: e,
	}
}

//GetAll 获取当前所有公告
func (ar *AnnouncementRepo) GetAllAnnouncement() ([]*models.Announcement, error) {
	beans := make([]*models.Announcement, 0)
	err := utils.Transaction(ar.engine, func(si *xorm.Session) error {
		return si.Find(&beans)
	})
	if err != nil {
		return nil, err
	}
	return beans, nil
}